<template>
	<view>
		<u-modal :show="show" title="未通过原因" showCancelButton @confirm="confirm" @cancel="cancel">
			<view class="slot-content">
				<u-list height="150">
					<u-list-item>
						<u-cell @click="choose(1)" :title="title[0]"></u-cell>
					</u-list-item>
					<u-list-item>
						<u-cell @click="choose(2)" :title="title[1]"></u-cell>
					</u-list-item>
					<u-list-item>
						<input class="input" @click="choose(3)" type="text" :value="value" placeholder="其他原因">
					</u-list-item>
				</u-list>
			</view>
		</u-modal>
		<scroll-view scroll-y="true">
			<view class="lists" v-for="item,index in lists" :key="item.id">
				<view class="top">
					<view>审核编号：{{item.id}}</view>
					<view class="status">{{statusLists[item.status+1]}}</view>
				</view>
				<view class="books">
					<image v-if="ImgUrl" class="img" :src="ImgUrl+item.identityCardFront" mode="aspectFit"></image>
					<image v-if="ImgUrl" class="img" :src="ImgUrl+item.identityCardReverse" mode="aspectFit"></image>
					<image v-if="ImgUrl" class="img" :src="ImgUrl+item.businessLicense" mode="aspectFit"></image>
				</view>
				<view class="bottom">
					<view class="user">
						<img class="imgggg" v-if="ImgUrl" :src="ImgUrl+item.avatar">
						<view class="username">{{item.username}}</view>
					</view>
					<view v-if="item.status==0" class="btn1" @click="toex(item.id,-1)">审核不通过</view>
					<view v-if="item.status==0" class="btn2" @click="toex(item.id,1)">审核通过</view>
				</view>
			</view>
		</scroll-view>
		<u-empty :show="!count" mode="data"
			icon="http://cdn.uviewui.com/uview/empty/data.png">
		</u-empty>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				BaseUrl: '',
				ImgUrl: '',
				token: '',
				lists: [],
				statusLists: ['未通过', '待审核', '已通过'],
				show: false,
				chooseWhat: '',
				value: '',
				id: '',
				index: '',
				title: ['图片模糊不清', '上传图片与所需无关'],
				page: 1,
				count:0
			}
		},
		onLoad() {
			this.BaseUrl = getApp().globalData.BaseUrl
			this.ImgUrl = getApp().globalData.ImgUrl
			this.token = uni.getStorageSync('token')
			this.toExamine()
		},
		onReachBottom() {
			this.page += 1;
			this.toExamine()
		},
		methods: {
			choose(e) {
				this.chooseWhat = e
				if (e == 1) {
					this.value = this.title[0]
				} else if (e == 2) {
					this.value = this.title[1]
				}
			},
			async toExamine() {
				await uni.request({
					url: this.BaseUrl + '/identity/list',
					method: "POST",
					header: {
						'Content-Type': 'application/json',
						'token': this.token
					},
					data: {
						page: this.page,
						limit: 5
					},
					success: (res) => {
						console.log("status",res)
						let result = res.data.data.data
						this.lists.push(...result)
						this.count=res.data.data.count
						// this.lists
					}
				})
			},
			confirm() {
				uni.request({
					url: this.BaseUrl + '/identity/audit',
					method: "POST",
					header: {
						'Content-Type': 'application/json',
						'token': this.token
					},
					data: {
						id: this.id,
						status: this.index,
						reason: this.value
					},
					success: (res) => {
						console.log("hello", res)
						this.lists.forEach(item => {
							if (item.id == this.id) {
								item.status = this.index
							}
						})
						this.show = false
					}
				})
			},
			cancel() {
				this.show = false
				this.value = ''
			},
			toex(id, index) {
				this.id = id
				this.index = index
				if (index == -1) {
					this.show = true
				} else if (index == 1) {
					this.value=''
					this.confirm()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.input {
		margin-top: 15upx;
		border-bottom: 1upx solid #888;
	}

	.lists {
		margin-top: 20upx;
		background-color: #fff;
		border-radius: 10upx;
		box-shadow: 0 0 5upx #888;

		.top {
			background-color: #fff;
			padding: 20upx 20upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			color: #888;
			font-size: 25upx;
			border-bottom: 1upx solid #cecece;

			.status {
				color: #ff5500;
				font-weight: bold;
			}
		}

		.books {
			display: flex;
			padding: 20upx;
			border-bottom: 1upx solid #e3e3e3;
			position: relative;

			.img {
				width: 180upx;
				height: 180upx;
				box-shadow: 0 0 5upx #888;
			}
		}

		.bottom {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20upx;
			position: relative;

			.user {
				display: flex;
				align-items: center;
				position: relative;

				.imgggg {
					height: 70upx;
					width: 70upx;
					border-radius: 50%;
					box-shadow: 0 0 2upx #888;
				}

				.username {
					margin-left: 20upx;
					font-size: 30upx;
				}

			}

			.btn1 {
				height: 60upx;
				width: 170upx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 30upx;
				box-shadow: 0 0 2upx #888;
				font-size: 25upx;
				color: #fff;
				background-color: rgb(255, 85, 0);
				position: relative;
				right: -270upx;
			}

			.btn2 {
				height: 60upx;
				width: 170upx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 30upx;
				box-shadow: 0 0 2upx #888;
				font-size: 25upx;
				background-color: $color;
				color: #fff;
				position: relative;
				right: 180upx;
			}
		}
	}
</style>
